package com.hualan.zhsq.service.impl.information;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hualan.zhsq.entity.information.ResidentInfo;
import com.hualan.zhsq.mapper.information.ResidentInfoMapper;
import com.hualan.zhsq.service.information.ResidentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ResidentInfoServiceImpl implements ResidentInfoService {

    @Autowired
    private ResidentInfoMapper residentInfoMapper;


    @Override
    public int add(ResidentInfo residentInfo) {
        return residentInfoMapper.insert(residentInfo);
    }

    @Override
    public int edit(ResidentInfo residentInfo) {
        return residentInfoMapper.updateById(residentInfo);
    }

    @Override
    public int remove(Integer id) {
        return residentInfoMapper.deleteById(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return residentInfoMapper.deleteByIds(Arrays.asList(ids));
    }

    @Override
    public List<ResidentInfo> find() {

        Page<ResidentInfo> residentInfoPage = residentInfoMapper.select(null, null);
        return residentInfoPage.getRecords();
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, ResidentInfo entity) {
        
        Page<ResidentInfo> page = new Page<>(pageNum, pageSize);
        Page<ResidentInfo> residentInfoPage = residentInfoMapper.select(page, null);
        long pages = residentInfoPage.getPages();
        long total = residentInfoPage.getTotal();
        List<ResidentInfo> residentInfos = residentInfoPage.getRecords();


        Map<String,Object> map = new HashMap<>();
        map.put("total",total);
        map.put("pages",pages);
        map.put("list",residentInfos);
        return map;
    }

    @Override
    public ResidentInfo findById(Integer id) {
        return null;
    }
}
